<?php
/**
 * Topic save action
 */
gatekeeper ();
// Get variables
$title = get_input ( "title" );
$desc = get_input ( "description" );
$container_guid = get_input ( 'group_guid' );
$rate = get_input ( "rate" );

elgg_make_sticky_form ( 'mark' );

// validation of inputs
if (! $title) {
	register_error ( elgg_echo ( 'Vui lòng nhập tiêu đề!' ) );
	forward ( REFERER );
	exit ();
}

$container = get_entity ( $container_guid );
if (! $container || ! $container->canWriteToContainer ( 0, 'object', 'mark' )) {
	register_error ( elgg_echo ( 'Có lỗi xảy ra, vui lòng liên hệ quản trị để biết thêm thông tin!' ) );
	forward ( REFERER );
}



$mark = new ElggObject ();
$mark->type = 'object';
$mark->subtype = 'mark';
$mark->title = $title;
$mark->access_id = ACCESS_LOGGED_IN;
$mark->description = $desc;
$mark->container_guid = $container_guid;
$mark->rate = $rate;
$mark->teacher_guid = elgg_get_logged_in_user_guid();
$mark->save ();

$project = get_entity ( $container->register_project );
if($project){
	$project->addRelationship($mark->guid, 'mark');
	//$project->addRelationship($mark->guid, 'mark');
}

elgg_clear_sticky_form ( 'mark' );


forward($container->getURL());

